package com.hospital.adapter;

import android.content.Context;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.hospital.BaseActivity.RootRegionActivity;
import com.hospital.Entity.Region;
import com.hospital.activity.R;
import com.hospital.view.GridView01;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjun on 2015/6/11.
 */
public class RootRegionAdapter extends SimpleBaseAdapter<Region> {

    private Context mContext;
    private boolean mIslogin;

    public RootRegionAdapter(Context context, List<Region> data,boolean islogin) {
        super(context, data);
        mContext = context;
        mIslogin = islogin;
    }

    @Override
    public int getItemResource() {
        return R.layout.item_region_select;
    }

    @Override
    public View getItemView(int position, View convertView, ViewHolder holder) {
        TextView regionName = holder.getView(R.id.region_name);
        GridView01 regionGridView = holder.getView(R.id.root_region_grid);
        Region region = getItem(position);
        final List<Region> subRegions = region.getSubRegions();
        regionName.setText(region.getProvince());
        regionGridView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.text4, getNames(subRegions)));
        regionGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                RootRegionActivity.getContext().cityOnSelect(subRegions.get(arg2));
            }
        });
        return convertView;
    }

    private List<String> getNames(List<Region> regions){
        List<String> names = new ArrayList<String>();
        for (Region region : regions){
            names.add(region.getName());
        }
        return names;
    }
}
